import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * @since 2019-12-27
 */
import { getEnvConfig } from "../utils/iocUtils";
import request from "../utils/request"; // import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';

var _getEnvConfig = getEnvConfig(),
    CPAAS_ADM = _getEnvConfig.CPAAS_ADM;
/**
 * 查询trace状态
 * @async
 * @param {object} params - 分配参数
 */


export function getTraceStatus() {
  return _getTraceStatus.apply(this, arguments);
}
/**
 * 开始trace
 * @async
 * @param {object} params - 分配参数
 */

function _getTraceStatus() {
  _getTraceStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_ADM, "/v1/trace/status"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _getTraceStatus.apply(this, arguments);
}

export function startTrace() {
  return _startTrace.apply(this, arguments);
}
/**
 * 结束trace
 * @async
 * @param {object} params - 分配参数
 */

function _startTrace() {
  _startTrace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_ADM, "/v1/trace/start"), {
              method: 'POST'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _startTrace.apply(this, arguments);
}

export function endTrace() {
  return _endTrace.apply(this, arguments);
}

function _endTrace() {
  _endTrace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_ADM, "/v1/trace/end"), {
              method: 'POST'
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _endTrace.apply(this, arguments);
}